using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Collections;

namespace Faust.Andrew.MTG
{
    public static class CardHelper
    {
        public static int NameComparer(Card x, Card y)
        {
            if (x == null && y == null) { return 0; }
            if (x == null && y != null) { return -1; }
            if (x != null && y == null) { return 1; }

            return String.Compare(x.Name, y.Name);
        }

        public static int ColorComparer(Card x, Card y)
        {
            if (x == null && y == null) { return 0; }
            if (x == null && y != null) { return -1; }
            if (x != null && y == null) { return 1; }

            return String.Compare(x.Color, y.Color);
        }

        public static int RarityComparer(Card x, Card y)
        {
            if (x == null && y == null) { return 0; }
            if (x == null && y != null) { return -1; }
            if (x != null && y == null) { return 1; }

            int xVal = GetRarityValue(x.Rarity);
            int yVal = GetRarityValue(y.Rarity);

            //We want to sort by rarest to least rare so we need to reverse the order
            //Because the rarest have the largest value.
            return yVal.CompareTo(xVal);
        }

        private static int GetRarityValue(string rarity)
        {
            switch (rarity)
            {
                case "Mythic Rare":
                    return 6;
                case "Special":
                    return 5;
                case "Rare":
                    return 4;
                case "Uncommon":
                    return 3;
                case "Common":
                    return 2;
                case "Basic Land":
                    return 1;
                default:
                    return 0;
                    
            }
        }

        public static int TypeComparer(Card x, Card y)
        {
            if (x == null && y == null) { return 0; }
            if (x == null && y != null) { return -1; }
            if (x != null && y == null) { return 1; }

            return String.Compare(x.CardTypes, y.CardTypes);
        }

        public static int OwnedComparer(Card x, Card y)
        {
            if (x == null && y == null) { return 0; }
            if (x == null && y != null) { return -1; }
            if (x != null && y == null) { return 1; }

            //We want to sort by most to least owned so we need to reverse the order
            //Because the the int comparer sorts in ascending order by default
            return y.Quantity.CompareTo(x.Quantity);            
        }

        public static int CostComparer(Card x, Card y)
        {
            if (x == null && y == null) { return 0; }
            if (x == null && y != null) { return -1; }
            if (x != null && y == null) { return 1; }

            return x.ConvertedManaCostNumeric.CompareTo(y.ConvertedManaCostNumeric);            
        }
    }
}